-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(snackbar): Auto Hide for Snackbar #1641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
CLAs look good, thanks! |
I signed it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change also needs unit tests.
*/ | ||
autoHideDuration: number | boolean; | ||
|
||
constructor(viewContainerRef: ViewContainerRef, autoHideDuration: number | boolean = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than being a constructor argument, this should just be a property that is set to the config with a default. We will shortly be giving the snackbar config the same treatment as the dialog config (#1679).
* If a value is provided the snackbar can still be dismissed normally. | ||
* If a snackbar is dismissed before the timer expires, the timer will be cleared. | ||
*/ | ||
autoHideDuration: number | boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just call this duration
, where the value is null
if it is persistent.
@@ -19,6 +19,8 @@ export class MdSnackBarRef<T> { | |||
/** Subject for notifying the user that the snack bar has closed. */ | |||
private _afterClosed: Subject<any> = new Subject(); | |||
|
|||
autoHide: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_autoDismissTimeoutId
@@ -36,6 +38,10 @@ export class MdSnackBarRef<T> { | |||
this._afterClosed.complete(); | |||
}); | |||
} | |||
// Clear autohide interval | |||
if (this.autoHide) { | |||
clearInterval(this.autoHide); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use setTimeout
, the corresponding cancel function is cancelTimeout
@@ -56,6 +54,12 @@ export class MdSnackBar { | |||
} else { | |||
mdSnackBarRef.containerInstance.enter(); | |||
} | |||
// Auto dismiss after timeout. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment like
// If the snackbar has a specified duration, set up a timeout to automatically dismiss it.
@@ -56,6 +54,12 @@ export class MdSnackBar { | |||
} else { | |||
mdSnackBarRef.containerInstance.enter(); | |||
} | |||
// Auto dismiss after timeout. | |||
if (config.autoHideDuration) { | |||
mdSnackBarRef.autoHide = setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the braces:
mdSnackBarRef._autoDismissTimeoutId =
setTimeout(() => mdSnackBarRef.dismiss(), config.duration);
Closing in favor of #1856 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I have created auto hide for snackbar.
autoHideDuration: number | boolean
- The number of milliseconds to wait before automatically dismissing. If no value is specified the snackbar will dismiss normally.autoHideDuration
option toMdSnackBarConfig
autoHideDuration
If no value is specified the snackbar will dismiss normally.r: @josephperrott